package com.example.genturedemo;

import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity2 extends AppCompatActivity implements GestureDetector.OnGestureListener {

    private GestureDetector detector;
    private static final String TAG = "mainTest";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);

        detector = new GestureDetector(this);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        return detector.onTouchEvent(event);
    }

    //触摸事件按下时触发
    @Override
    public boolean onDown(@NonNull MotionEvent e) {
        Log.e(TAG, "onDown: " );
        Toast.makeText(this,"onDown",Toast.LENGTH_SHORT).show();
        return false;
    }

    //用户手指触摸屏幕按下,但是未移动或松开时触发
    @Override
    public void onShowPress(@NonNull MotionEvent e) {
        Log.e(TAG, "onShowPress: " );
        Toast.makeText(this,"onShowPress",Toast.LENGTH_SHORT).show();
    }

    //用户轻点屏幕时]触发
    @Override
    public boolean onSingleTapUp(@NonNull MotionEvent e) {
        Log.e(TAG, "onSingleTapUp: " );
        Toast.makeText(this,"onSingleTapUp",Toast.LENGTH_SHORT).show();
        return false;
    }

    //在屏幕上滑动触发
    @Override
    public boolean onScroll(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float distanceX, float distanceY) {
        Log.e(TAG, "onScroll: " );
        Toast.makeText(this,"onScroll",Toast.LENGTH_SHORT).show();
        return false;
    }

    //在屏幕长按触发
    @Override
    public void onLongPress(@NonNull MotionEvent e) {
        Log.e(TAG, "onLongPress: " );
        Toast.makeText(this,"onLongPress",Toast.LENGTH_SHORT).show();
    }

    //用户在屏幕滑动结束后触发
    @Override
    public boolean onFling(@NonNull MotionEvent e1, @NonNull MotionEvent e2, float velocityX, float velocityY) {
        Log.e(TAG, "onFling: " );
        Toast.makeText(this,"onFling",Toast.LENGTH_SHORT).show();
        return false;
    }
}